home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-05-01 | 3.2 KB | 233 lines | [04] ASCII Text (0x0000) |
- %
- 3
- 14
- 1
- 38
- ALL ABOUT VARIABLES
-
- Since you're a curious person
- (after all, you made it this far),
- you're probably wondering how the
- computer asks for and remembers
- your name. Stay tuned. This
- section will teach you how that's
- done.
- ^
- %
- 20
- 24
- 1
- 38
- The computer's memory is a lot
- like hundreds of mailboxes.
- ^
- &
- Each mailbox can contain
- different information.
- ^
- &
- And each mailbox has a name that
- sets it apart from other boxes.
- ^
- &
- These mailboxes in memory are
- called variables.
- ^
- &
- And the name given to each box in
- memory is called a variable name.
- ^
- %
- 3
- 10
- 1
- 38
- A variable name is made up of
- letters and numbers. For this
- example, we've chosen the name A
- (which just happens to stand for
- Apple).
- ^
- %
- 3
- 12
- 1
- 38
- For the variable A to be of any
- use to you, you must assign
- some information to it. The
- question is, how do you assign
- information--such as numbers,
- words, or equations (like 3+4)--to
- a variable?
- ^
- &
- One way to do this is to use
- the LET statement. The LET
- statement assigns information
- (in this case a number)
- to the variable.
- ^
- %
- 3
- 7
- 1
- 38
- The LET statement looks like
- this...
- ^
- %
- 3
- 7
- 1
- 38
- First, you must type a line
- number. In this case, line 10.
- ^
- &
- Next, you type LET...
- ^
- &
- followed by the variable name.
- In this case, A.
- ^
- &
- The next step is to type an equal
- sign (=).
- ^
- &
- Then type the number you want
- to assign to the variable.
- ^
- %
- 3
- 10
- 1
- 38
- The number 33 is now stored under
- the name A. Now instead of asking
- the Apple II to print 33, you
- can ask it to PRINT the contents
- of A, which is 33.
- ^
- &
- Do you know what to type to tell
- the computer to print the contents
- of A? If so, type it now on line
- 20. (If you're not sure what to
- do now, press RETURN for a hint.)
- ^
- %
- 3
- 8
- 1
- 38
- You did it! To complete your
- three-line program, type an END
- statement on line 30.
- ^
- %
- 3
- 9
- 1
- 38
- You're becoming a first-rate
- programmer! Now run the program
- and look at the result of your
- work.
- ^
- %
- 3
- 10
- 1
- 38
- Congratulations! You've just
- written a program using variables.
- Would you like a bit more
- explanation of how this program
- works? (Y/N)
- ^
- %
- 3
- 10
- 1
- 38
- Variables are somewhat exclusive
- in that they hold only one thing
- at a time. If you assign a new
- value to the variable A, the
- old value is replaced.
- ^
- &
- Try it yourself. Replace the
- old LET statement on line 10 with
- a new one and assign different
- contents to A.
- ^
- %
- 3
- 7
- 1
- 38
- Now run the program and notice
- the new contents of A.
- ^
- %
- 3
- 10
- 1
- 38
- See, we weren't kidding. The
- contents of variable A changed
- from 33 to
- ^
- &
- There are two ways to assign
- information to variables. You
- just learned how to assign
- something to a variable inside a
- program.
- ^
- &
- One way to change the contents
- is to rewrite the LET statements
- whenever you want to change the
- numbers.
- ^
- %
- 3
- 10
- 1
- 38
- The second way is to let you
- enter information from the
- keyboard while the program is
- running. This involves using the
- INPUT statement.
- ^
- %
- 3
- 9
- 1
- 38
- First of all, please clear the
- computer's memory. (Press RETURN
- for a hint if you're not sure of
- what to do.)
- ^
- %
- 3
- 9
- 1
- 38
- Good job. You're doing well.
- We've taken the liberty of writing
- a number game program to help
- explain the INPUT statement.
- ^
- &
- We saved the program on the disk
- under the name NUMBER. Please
- load the NUMBER program now.
- ^
-